package checkers3d.presentation;

import java.awt.*;

/**
 * A visible GUI component that exists as a bitmapped image.
 *
 * @author      Ruben Acuna
 */
public class GUIPictureBox implements IDrawable
{
    /**
    * The position of this component within a GUIContainer or window space.
    */
    private Point position;

    /**
    * The IRenderResource (always a RenderResourceBitmap) that defines how the
    * component looks.
    */
    private IRenderResource resource;

    /**
    * Class constructor that loads image data from a file and positions it at
    * the coordinates passed.
    *
    * @param filename A relative path to a file containing an image.
    * @param position The position of this object relative to its container.
    * @see RenderResourceBitmap
    */
    public GUIPictureBox(String filename, Point position)
    {
        setDrawPosition(position);
        setRenderResource(new RenderResourceBitmap(filename));
    }

    /**
    * Class constructor that uses a preexisting BufferedImage for image data and
    * positions it at the coordinates passed.
    *
    * @param resource   A BufferedImage that will be used for image data.
    * @param position   The position of this object relative to its container.
    * @see RenderResourceBitmap
    */
    public GUIPictureBox(RenderResourceBitmap resource, Point position)
    {
        setDrawPosition(position);
        setRenderResource(resource);
    }
    /**
    * Class constructor that uses a preexisting BufferedImage for image data and
    * positions it at (0,0).
    *
    * @param resource   A BufferedImage that will be used for image data.
    * @see RenderResourceBitmap
    */
    public GUIPictureBox(RenderResourceBitmap resource)
    {
        setDrawPosition(new Point());
        setRenderResource(resource);
    }

    /**
    * Returns the position of the GUIPictureBox.
    *
    * @return The position of this GUIPictureBox.
    * @see IDrawable
    */
    public Point getDrawPosition()
    {
        return position;
    }

    /**
    * Sets the current the position of the GUIPictureBox.
    *
    * @param  position The new position of this GUIPictureBox.
    * @see IDrawable
    */
    public void setDrawPosition(Point position)
    {
        this.position = position;
    }

    /**
    * Returns the IRenderResource of the GUIPictureBox.
    *
    * @return The IRenderResource of this GUIPictureBox.
    * @see IDrawable
    */        
    public IRenderResource getRenderResource()
    {
        return resource;
    }

    /**
    * Sets the current the IRenderResource of the GUIPictureBox.
    *
    * @param  resource The new IRenderResource of this GUIPictureBox.
    */
    public void setRenderResource(IRenderResource resource)
    {
        this.resource = resource;
    }

    /**
    * Returns a string representation of the GUIPictureBox which contains
    * information about its position and IRenderResource.
    *
    * @return       A string representation of this GUIPictureBox.
    */
    @Override
    public String toString()
    {
        return getClass().getName() + " -> "
                                    + position.toString()
                                    + ", " + resource.toString();
    }
}